package de.baumann.browser.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import de.baumann.browser.R;
import de.baumann.browser.api.net.vo.Licence;

/**
 * @author:junce
 * @date:2019/1/4 16:54
 * @discription: licence 列表适配器
 */
@SuppressWarnings("ALL")
public class LicenceListAdapter extends BaseQuickAdapter<Licence, BaseViewHolder> {

    public LicenceListAdapter(int layoutResId) {
        super(layoutResId);
    }

    private int checkedPosition = 0;

    @SuppressWarnings("AliDeprecation")
    @Override
    protected void convert(BaseViewHolder holder, Licence licence) {
        TextView tvLicenceName = holder.getView(R.id.tvLicenceName);
        tvLicenceName.setText(licence.getLisence());
        holder.setText(R.id.tvValidityPeriod, mContext.getString(R.string.validity_period) + licence.getExpirationStr());
        ImageView ivSel = holder.getView(R.id.ivSel);
        if (holder.getLayoutPosition() == checkedPosition) {
            ivSel.setVisibility(View.VISIBLE);
        } else {
            ivSel.setVisibility(View.INVISIBLE);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkedPosition = holder.getLayoutPosition();
                notifyDataSetChanged();
            }
        });
    }

    public String getLicenceId() {
        return mData.get(checkedPosition).getLicenceId();
    }
}
